﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Jb.Web.ViewModels;

namespace Jb.Web.Utility
{
    public static class UserInfo
    {
        /// <summary>
        /// Determines whether the currently logged in user is a Admin or not
        /// </summary>
        public static bool IsAdmin
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfAdmin)
                    return true;
                return false;
            }
        }

        /// <summary>
        /// Determines whether the currently logged in user is a Job Seeker
        /// </summary>
        public static bool IsJobSeeker
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfJobSeeker)
                    return true;
                return false;
            }
        }

        /// <summary>
        /// Determines whether the currently logged in user is a Company User
        /// </summary>
        public static bool IsCompanyUser
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.Contact != null)
                    return true;
                return false;
            }
        }

        /// <summary>
        /// Determines whether the currently logged in user is a Company Admin
        /// </summary>
        public static bool IsCompanyAdmin
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.Contact != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfCompanyAdmin)
                    return true;
                return false;
            }
        }

        /// <summary>
        /// Determines whether the currently logged in user is a Company Employee user
        /// </summary>
        public static bool IsCompanyEmployeeUser
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.Contact != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfCompanyUser)
                    return true;
                return false;
            }
        }

        /// <summary>
        /// Gets the currently logged in users group name
        /// </summary>
        /// <returns></returns>
        public static String GetUserType()
        {
            if (SessionCache.CurrentUser != null)
            {                
                GroupViewModel group = ApplicationCache.UserGroups.FirstOrDefault(P => P.ID == SessionCache.CurrentUser.GroupID);
                return group.Name;
            }
            return "Not Logged In";
        }

        /// <summary>
        /// Gets the email address of currently logged in user. 
        /// </summary>
        /// <returns></returns>
        public static String GetEmail()
        {
            if (UserInfo.IsJobSeeker)
                return SessionCache.CurrentUser.JobSeeker.Address.Email;
            else if (UserInfo.IsCompanyUser)
                return SessionCache.CurrentUser.Contact.Address.Email;            

            return String.Empty;
        }
    }

    #region User Menu Enumerations

    public enum JobSeekerMenu
    {
        Dashboard,
        Profile,
        Coverletter,
        Resume,
        FaboriteJobs,
        AppliedJobs,
        InterviewRequests,
        None
    }
    public enum EmployerMenu
    {
        Dashboard,
        CompanyProfile,
        ManageJobs,
        ManageContacts,
        SearchResume,
        FavoriteResumes,
        PublishedJobs,
        ManageApplications,
        FavoriteJobSeekers,
        Subscriptions,
        Settings,
        None
    }
    public enum AdminMenu
    {
        Dashboard,
        ManageLookupData,
        ManagePackage,
        ManageContents,
        ManageCategory,
        SearchConfig,
        Settings,
        None
    }

    #endregion
}